<template>
  <div>
      <div class="register_con">
        <div class="l_con fl">
            <a class="reg_logo"><img src="/static/images/logo.png"></a>
            <div class="reg_slogan">商品美 · 种类多 · 欢迎光临</div>
            <div class="reg_banner"></div>
        </div>

        <div class="r_con fr">
            <div class="reg_title clearfix">
                <h1>用户注册</h1>
                <a href="/login.html">登录</a>
            </div>
            <div class="reg_form clearfix" id="app">
                <form>
                    <ul>
                        <li>
                            <label>用户名:</label>
                            <input type="text" v-model="username" name="user_name" id="user_name" @blur="check">
                            <span v-show="is_check" class="error_tip">{{ check_msg }}</span>
                        </li>
                        <li>
                            <label>密码:</label>
                            <input type="password" v-model="password" name="pwd" id="pwd">
                        </li>
                        <li>
                            <label>确认密码:</label>
                            <input type="password" v-model="password2" name="cpwd" id="cpwd">
                        </li>
                        <li>
                            <label>手机号:</label>
                            <input type="text" name="phone" v-model="mobile" id="phone">
                        </li>
                        <li>
                            <!-- <label>短信验证码:</label> -->
                            <label>邮箱:</label>
                            <input type="text" v-model="sms_code" name="msg_code" id="msg_code" class="msg_input">
                        </li>
                        <li class="agreement">
                            <input type="checkbox" name="allow" id="allow" checked="checked">
                            <label>同意”美多商城用户使用协议“</label>
                            <span class="error_tip2">请勾选同意</span>
                        </li>
                        <li class="reg_sub">
                            <input type="button" value="注 册" name="" @click="register">
                        </li>
                    </ul>
                </form>
            </div>

        </div>

    </div>

    <div class="footer no-mp">
        <div class="foot_link">
            <a href="#">关于我们</a>
            <span>|</span>
            <a href="#">联系我们</a>
            <span>|</span>
            <a href="#">招聘人才</a>5
            <span>|</span>
            <a href="#">友情链接</a>
        </div>
        <p>CopyRight © 2016 北京美多商业股份有限公司 All Rights Reserved</p>
        <p>电话：010-****888 京ICP备*******8号</p>
    </div>
  </div>
</template>

<script>
import axios from 'axios'
export default {
    data(){
        return{
            username:'',
            password:'',
            password2:'',
            mobile:'',
            sms_code:'',
            role:1,
            is_check:false,
            check_msg:''
        }
    },
    methods:{
        check(){
            axios({
                url:'http://127.0.0.1:8000/app01/check/',
                method:'get',
                params:{'username':this.username,'password1':this.password,'password2':this.password2,'phone':this.mobile,'email':this.sms_code}
            }).then(res=>{
                console.log(res)
                if(res.data.code==400){
                    this.is_check = true
                    this.check_msg = res.data.msg
                    console.log(this.is_check)
                }
            })
        },
        register(){
            let form_data = new FormData()
            form_data.append('username',this.username)
            form_data.append('password1',this.password)
            form_data.append('password2',this.password2)
            form_data.append('phone',this.mobile)
            form_data.append('email',this.sms_code)
            form_data.append('role',this.role)
            axios({
                url:'http://127.0.0.1:8000/app01/register/',
                method:'post',
                data:form_data
            }).then(res=>{
                console.log(res.data)
            })
        }
    }
}
</script>

<style>

</style>